home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / hmaglue.asm < prev    next >
Encoding:
Assembly Source File  |  1993-11-13  |  11.0 KB  |  378 lines

  1. ;************************************************
  2. ;***                                          ***
  3. ;***    Contains definitions for XMS routines ***
  4. ;***                                          ***
  5. ;************************************************
  6.  
  7. ;
  8. ;   Define the extended function interrupt which gives us the
  9. ;   XMS handler address:
  10. ;
  11. XFunc       equ     2fh
  12.  
  13. ;
  14. ;   Define the function code for XMS, and the two sub-codes:
  15. ;
  16. XFuncXMS        equ     43h
  17. XFuncXMSPres    equ     0h
  18. XFuncXMSEntry   equ     10h
  19.  
  20. ;
  21. ;   Define the XMSPresent response:
  22. ;
  23. XMSPresent      equ     80h
  24.  
  25.  
  26. ;
  27. ;   Now define the 2.0 XMS function codes.
  28. ;   These are 8 bit values which are loaded into
  29. ;   AH before calling the XMS handler (the address of which
  30. ;   was determined using XFuncXMSEntry int).
  31. ;
  32. XMSGetVersion   equ     00h
  33. XMSAllocHMA     equ     01h
  34. XMSFreeHMA      equ     02h
  35. XMSGlobEnabA20  equ     03h
  36. XMSGlobDisabA20 equ     04h
  37. XMSLocEnabA20   equ     05h
  38. XMSLocDisabA20  equ     06h
  39. XMSGetA20State  equ     07h
  40. XMSGetFreeXM    equ     08h
  41. XMSAllocXM      equ     09h
  42. XMSFreeXM       equ     0ah
  43. XMSMoveXM       equ     0bh
  44. XMSLockXM       equ     0ch
  45. XMSUnlockXM     equ     0dh
  46. XMSGetHandInfo  equ     0eh
  47. XMSResizeXM     equ     0fh
  48. XMSAllocUM      equ     10h
  49. XMSFreeUM       equ     11h
  50.  
  51.  
  52. ;
  53. ;   Now define the XMS error codes:
  54. ;
  55. XMSErrOK        equ     00h     ; No error
  56. XMSErrUnimp     equ     80h     ; Unimplemented function
  57. XMSErrVDISK     equ     81h     ; VDISK device detected
  58. XMSErrA20       equ     82h     ; A20 error
  59. XMSErrNoHMA     equ     90h     ; HMA does not exist
  60. XMSErrHMAInUse  equ     91h     ; HMA already in use
  61. XMSErrHMAMin    equ     92h     ; HMA space req. < /HMAMIN= parameter
  62. XMSErrHMANotAll equ     93h     ; HMA not allocated
  63. XMSErrA20Enab   equ     94h     ; A20 still enabled
  64. XMSErrNoXMLeft  equ     0A0h    ; All XM allocated
  65. XMSErrNoHandles equ     0A1h    ; All handles are allocated
  66. XMSErrHandInv   equ     0A2h    ; Invalid handle
  67. XMSErrSHandInv  equ     0A3h    ; Invalid Source Handle
  68. XMSErrSOffInv   equ     0A4h    ; Invalid Source Offset
  69. XMSErrDHandInv  equ     0A5h    ; Invalid Dest Handle
  70. XMSErrDOffInv   equ     0A6h    ; Invalid Dest Offset
  71. XMSErrLenInv    equ     0A7h    ; Invalid Length
  72. XMSErrOverlap   equ     0A8h    ; Invalid move overlap
  73. XMSErrParity    equ     0A9h    ; Parity error
  74. XMSErrNoLock    equ     0AAh    ; Handle not locked
  75. XMSErrLock      equ     0ABh    ; Handle Locked
  76. XMSErrLockOvflo equ     0ACh    ; Lock count overflo
  77. XMSErrLockFail  equ     0ADh    ; Lock fail
  78. XMSErrSmUMB     equ     0B0h    ; Smaller UMB available
  79. XMSErrNoUMB     equ     0B1h    ; No UMB's available
  80. XMSErrUMBInv    equ     0B2h    ; Invalid UMB segment
  81.  
  82.  
  83. ;
  84. ;   Define the Bios interrupt and function codes
  85. ;
  86. XMSBios         equ     15h
  87.  
  88. ;
  89. ;   Define the two function codes
  90. ;
  91. XMSBiosXMMove   equ     87h     ; Move a block of XMS
  92. XMSBiosXMSize   equ     88h     ; Get size of extended memory
  93.  
  94. ;
  95. ;   Define the access byte
  96. ;
  97. XMSBiosAccess   equ     93h     ; The "correct" access byte
  98.  
  99.  
  100. ;**************************************************************
  101. ;***                                                        ***
  102. ;***    int xms_init()                                      ***
  103. ;***                                                        ***
  104. ;***    Initializes the XMS interface. Returns a zero       ***
  105. ;***    if interface successfully initialized.              ***
  106. ;***                                                        ***
  107. ;**************************************************************
  108.  
  109. ;--------------------------------------
  110. ;
  111. ; Declare memory model and language
  112. ;
  113.  
  114.         .Model  Large,C     
  115.  
  116. ;--------------------------------------
  117. ;
  118. ; Declare error WORD as extrn to this
  119. ; module
  120. ;
  121.  
  122.         extrn   errno:WORD 
  123.  
  124. ;--------------------------------------
  125. ;
  126. ; Declare function as PUBLIC
  127. ;
  128.  
  129.         public  xms_init
  130.         public  xmsHandler
  131.  
  132.         .Data
  133.  
  134. ;
  135. ;   Define the xmsHandler address which will be used
  136. ;   for calls to XMS.
  137. ;
  138. xmsHandler      dd      xms_defaultHandler
  139.  
  140. ;--------------------------------------
  141. ;
  142. ; Begin code segment
  143. ;
  144.  
  145.         .Code
  146.  
  147. xms_init    proc
  148.  
  149.         mov     ah,XFuncXMS     ; XMS functions
  150.         mov     al,XFuncXMSPres ; Determine is XMS present
  151.         int     XFunc           ; Call extended functions
  152.  
  153.         cmp     al,XMSPresent   ; See if it's there
  154.         jne     noXMS           ; Nope, return an error
  155.  
  156.     ;
  157.     ;   It's there, so let's get the handler address:
  158.     ;
  159.         mov     ah,XFuncXMS     ; XMS functions
  160.         mov     al,XFuncXMSEntry; Get handler entry point
  161.         int     XFunc           ; Call extended functions
  162.  
  163.         mov     word ptr xmsHandler,bx      ; Handler offset
  164.         mov     word ptr xmsHandler+2,es    ; Handler segment
  165.  
  166.         mov     ax,XMSErrOK     ; no error
  167.         ret
  168.  
  169. noXMS:
  170.         mov     ax,XMSErrUnimp  ; No XMS (Unimplemented function)
  171.         mov     errno,ax        ; Copy to errno
  172.         ret
  173.  
  174. xms_init    endp                ; end of procedure
  175.  
  176. ;
  177. ;   The xms_default_handler is used so that a call to
  178. ;   xmsHandler before XMS is initialized will return an
  179. ;   error. This is replaced by the actual handler when
  180. ;   xms_init is called.
  181. ;
  182. xms_defaultHandler      proc
  183.  
  184.         xor     ax,ax           ; ax to zero means error
  185.         mov     bl,XMSErrUnimp  ; Unimplemented function
  186.         ret
  187.  
  188. xms_defaultHandler      endp
  189.  
  190.  
  191.  
  192. ;**************************************************************
  193. ;***                                                        ***
  194. ;***    int xms_allocHMA(WORD hmaBytes)                     ***
  195. ;***                                                        ***
  196. ;***    Allocates the High Memory Area to the program.      ***
  197. ;***    HmaBytes specifies the amount of HMA which the      ***
  198. ;***    the program intends to use. If it asks for a        ***
  199. ;***    sufficient amount, the request will be granted.     ***
  200. ;***                                                        ***
  201. ;**************************************************************
  202.  
  203.         .model  large,C   
  204.  
  205.         extrn   errno:WORD  
  206.  
  207. ;
  208. ;   Define entry point
  209. ;
  210.         public  xms_allocHMA
  211.  
  212.         .code
  213.  
  214. xms_allocHMA    proc    hmaBytes:Word
  215.  
  216.         mov     dx,hmaBytes         ; Amount the app expects to use
  217.         mov     ah,XMSAllocHMA      ; Function code
  218.         call    xmsHandler          ; call the guy
  219.  
  220.         or      ax,ax               ; AX=0 means error
  221.         jz      errorReturn
  222.  
  223.         mov     ax,XMSErrOK         ; No error
  224.         ret
  225.  
  226. errorReturn:
  227.         mov     al,bl               ; Move error code to AL
  228.         xor     ah,ah               ; Zero extend to 16 bits
  229.         mov     errno,ax            ; Copy to errno
  230.         ret
  231.  
  232. xms_allocHMA    endp                ; end of procedure
  233.  
  234.  
  235. ;**************************************************************
  236. ;***                                                        ***
  237. ;***    int xms_freeHMA()                                   ***
  238. ;***                                                        ***
  239. ;***    Frees the High Memory Area.                         ***
  240. ;***                                                        ***
  241. ;**************************************************************
  242.  
  243.         .model  large,C   
  244.  
  245.         extrn   errno:WORD  
  246.  
  247. ;
  248. ;   Define entry point
  249. ;
  250.         public  xms_freeHMA
  251.  
  252.         .code
  253.  
  254. xms_freeHMA     proc
  255.  
  256.         mov     ah,XMSFreeHMA       ; Function code
  257.         call    xmsHandler          ; call the guy
  258.  
  259.         or      ax,ax               ; AX=0 means error
  260.         jz      errorReturn
  261.  
  262.         mov     ax,XMSErrOK         ; No error
  263.         ret
  264.  
  265. xms_freeHMA     endp                ; end of procedure
  266.  
  267.  
  268. ;**************************************************************
  269. ;***                                                        ***
  270. ;***    int xms_globEnabA20()                               ***
  271. ;***                                                        ***
  272. ;***    Enables the A20 address line allowing 21 bit        ***
  273. ;***    addressing and access to the HMA                    ***
  274. ;***                                                        ***
  275. ;**************************************************************
  276.  
  277.         .model  large,C   
  278.  
  279.         extrn   errno:WORD  
  280.  
  281. ;
  282. ;   Define entry point
  283. ;
  284.         public  xms_globEnabA20
  285.  
  286.         .code
  287.  
  288. xms_globEnabA20 proc
  289.  
  290.         mov     ah,XMSGlobEnabA20   ; Function code
  291.         call    xmsHandler          ; call the guy
  292.  
  293.         or      ax,ax               ; AX=0 means error
  294.         jz      errorReturn
  295.  
  296.         mov     ax,XMSErrOK         ; No error
  297.         ret
  298.  
  299. xms_globEnabA20 endp                ; end of procedure
  300.  
  301.  
  302.  
  303. ;**************************************************************
  304. ;***                                                        ***
  305. ;***    int xms_globDisabA20()                              ***
  306. ;***                                                        ***
  307. ;***    Disables the A20 address line.                      ***
  308. ;***                                                        ***
  309. ;**************************************************************
  310.  
  311.         .model  large,C   
  312.  
  313.         extrn   errno:WORD  
  314.  
  315. ;
  316. ;   Define entry point
  317. ;
  318.         public  xms_globDisabA20
  319.  
  320.         .code
  321.  
  322. xms_globDisabA20    proc
  323.  
  324.         mov     ah,XMSGlobDisabA20  ; Function code
  325.         call    xmsHandler          ; call the guy
  326.  
  327.         or      ax,ax               ; AX=0 means error
  328.         jz      errorReturn
  329.  
  330.         mov     ax,XMSErrOK         ; No error
  331.         ret
  332.  
  333. xms_globDisabA20    endp            ; end of procedure
  334.  
  335.  
  336.  
  337. ;**************************************************************
  338. ;***                                                        ***
  339. ;***    int xms_getA20State(WORD *a20State)                 ***
  340. ;***                                                        ***
  341. ;***    Returns the enable status of the A20 line.          ***
  342. ;***    A20State is TRUE (1) on return if A20 is enabled,   ***
  343. ;***    otherwise it is FALSE (0).                          ***
  344. ;***                                                        ***
  345. ;**************************************************************
  346.  
  347.         .model  large,C   
  348.  
  349.  
  350.         extrn   errno:WORD  
  351.  
  352. ;
  353. ;   Define entry point
  354. ;
  355.         public  xms_getA20State
  356.  
  357.         .code
  358.  
  359. xms_getA20State proc    a20State:Far Ptr Word
  360.  
  361.         mov     ah,XMSGetA20State   ; Function code
  362.         call    xmsHandler          ; call the guy
  363.  
  364.         or      ax,ax               ; AX=0 may mean error
  365.         jnz     goodReturn          ; AX<>0 means A20 enabled
  366.         or      bl,bl               ; BL<>0 means error
  367.         jnz     errorReturn
  368.  
  369. goodReturn:
  370.         les     bx,a20State         ; Address to return result
  371.         mov     es:[bx],ax          ; Flag gives A20 state
  372.         mov     ax,XMSErrOK         ; No error
  373.         ret
  374.  
  375. xms_getA20State endp                ; end of procedure
  376.  
  377.         End
  378.